package com.huanke.iot.api.controller.h5.iot;

import com.alibaba.fastjson.JSONObject;
import com.huanke.iot.api.controller.h5.BaseController;
import com.huanke.iot.api.service.device.basic.DeviceIotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/iot")
@RestController
@Slf4j
public class IotController extends BaseController {
    @Autowired
    private DeviceIotService deviceIotService;
    /**
     * 从设备列表
     * @return
     */
    @GetMapping("/high/childDeviceList/{hostDeviceId}")
    public Object childDeviceList(@PathVariable("hostDeviceId") Integer hostDeviceId){
        log.info("iot从设备列表：hostDeviceId={}", hostDeviceId);
        JSONObject childDeviceVoList = deviceIotService.childDeviceList(hostDeviceId);
        return childDeviceVoList;
    }

    /**
     * 修改从设备列表
     * @return
     */
    @PostMapping("/high/updateChildDevice/{hostDeviceId}")
    public Object updateChildDevice(@PathVariable("hostDeviceId") Integer hostDeviceId, @RequestBody JSONObject updateObj) throws Exception {
        Boolean result = deviceIotService.updateChildDevice(hostDeviceId, updateObj);
        return result;
    }

    /**
     * 后台向设备提供接口，用于查询配置文件列表。
     * @param modelNo
     * @return
     */
    @GetMapping("config/{modelNo}")
    public Object config(@PathVariable("modelNo") String modelNo){
        JSONObject config = deviceIotService.config(modelNo);
        return config;
    }
}
